//
//  main.cpp
//  cplusplusLearn
//
//  Created by mac on 12-3-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <vector>
#include <fstream>
#include <bitset>

using namespace std;

enum open_modes{ input = 1, output, append };
enum Points { point2d = 2, point2w, point3d = 3, point3w };
void vectSort();
void vectSort(){
    int ia[10]={51,23,7,83,411,98,12,103,37,6};
    
    vector<int> vec1(ia,ia+10);
    
    cout<<"pre Sort...\n";
    for (int i=0; i<10; i++) {
        cout<<i<<":"<<vec1[i]<<"\n"<<std::endl;
    }
    
    sort(vec1.begin(), vec1.end());
    cout<<"##############\n";
    for (int i=0; i<10; i++) {
        cout<<i<<":"<<vec1[i]<<"\n";
    }
}

vector<string>* retrive_text();

int main (int argc, const char * argv[])
{
    
    //const char *st = "The expense of spirit\n";
//string st( "The expense of spirit\n" );
//    
//    
//    st.c_str();
//    int len = 0;
////    while ( *st++ ) ++len;
//    
//    cin>>len;
//    
//    cout << st << " size is : " << st.size() << endl;
//    // insert code here...
//    std::cout << "你好！ Xcode\n"<<"China\n"<<len<<(point2w==point3d);
//    //vectSort();
//    
//    int *p=new int[3];
//    cout<<"p="<<sizeof(p)<<"*p="<<sizeof(*p)<<endl;
//    long ival=36577;
//    cout<<"sizeof(6)="<<sizeof(ival)<<"6<<2="<<(ival<<40)<<endl;
//    bitset<32> bit;
//    int a=6,b=6;
//    a=a++ + ++b;
//    cout<<a<<b;
    
    
    string numerics( "0123456789" );
    string name( "r2d5dd4" );
    
    string::size_type pos=0;
    
    while ((pos = name.find_first_of( numerics ,pos))!=string::npos) {
        cout << "found numeric at index: "
        << pos << "\telement is "<<name[pos]<<endl;
        ++pos;
    }
  //  string::size_type pos = name.find_first_of( numerics );
    
    //retrive_text();
    
    return 0;
}

vector<string>* retrive_text(){
    string file_name;

    cout<<"Input File Name:";
    cin>>file_name;

    
    ifstream infile(file_name.c_str(),ios::in);
    
    if (!infile) {
        cerr<<"Open Error";
        exit(-1);
    }
    else{
        cout<<endl;
    }
    vector<string>* lines_of_text =new vector<string>;
    
    string textline;
    
    typedef pair<string::size_type, int> stats;
    
    stats maxline;
    
    int linenum=0;
    
    while (getline(infile, textline, '\n')) {
        cout<<"read line "<<linenum+1<<"string:"<<textline<<endl;
        if (maxline.first<<textline.size()) {
            maxline.first=textline.size();
            maxline.second=linenum;
            
        }
        
        lines_of_text->push_back(textline);
        linenum++;
    }
    
    return lines_of_text;
}
